home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume3 / xcmap / patch1 < prev    next >
Encoding:
Internet Message Format  |  1989-02-08  |  6.4 KB

  1. Path: uunet!wyse!mikew
  2. From: mikew@wyse.wyse.com (Mike Wexler)
  3. Newsgroups: comp.sources.x
  4. Subject: v03i011:  display the default colormap, Patch1
  5. Message-ID: <2045@wyse.wyse.com>
  6. Date: 8 Feb 89 23:22:33 GMT
  7. Organization: Wyse Technology, San Jose
  8. Lines: 166
  9. Approved: mikew@wyse.com
  10.  
  11. Submitted-by: bradley@dsl.cis.upenn.edu (John Bradley)
  12. Posting-number: Volume 3, Issue 11
  13. Archive-name: xcmap/patch1
  14.  
  15.  
  16.  
  17. This corrects two bugs in xcmap.  The first bug had to do with X Servers that
  18. didn't return a power of 2 on the function "XDisplayCells()".  The program
  19. wouldn't run on them.  The second bug occurred when you dragged the mouse 
  20. outside of the window.  It would return out-of-value pixels, and eventually
  21. crash.
  22.  
  23. diff -c xcmap/README xcmapnew/README
  24. *** xcmap/README    Wed Feb  8 17:25:35 1989
  25. --- xcmapnew/README    Wed Feb  8 17:10:10 1989
  26. ***************
  27. *** 1,3 ****
  28. --- 1,47 ----
  29.   xcmap is a program that displays the contents of the default colormap on 
  30.   4-, 6-, and 8-bit X11 displays.  It displays the colormap both as a grid of
  31.   colored rectangles, and as RGB components.
  32. + This is a very useful thing to anybody who's trying to do color-intensive
  33. + programs (such as displaying GIF pictures...) on X.
  34. + It's also kind of neat to watch.
  35. + John Bradley  -  bradley@cis.upenn.edu
  36. + PATCH 1:
  37. +   Contributed by Dave Gorgen / Apollo Computer Inc (dpg@citi.umich.edu)
  38. +   Allows xcmap to run on X servers that pre-allocate colors for the cursor,
  39. +   returning an "XDisplayCells()" value != a power of 2.  This would include
  40. +   Apollos, DEC QDSSs, and no doubt some other machines.
  41. + -------------
  42. + (The full description of the problem, from Dave's letter...)
  43. +     I was happy to see xcmap posted on comp.sources.x; it's one of those
  44. + programs I always meant to write but never got around to.
  45. +     However, when I ran it on my Apollo server I got:
  46. + xcmap: dispcells = 254.  This program can only deal with 4, 6, and 8-bit display
  47. + s.
  48. +     The problem is that xcmap, like many color X clients, incorrectly assumes
  49. + that if a visual is n bits deep, it must support exactly 2**n colormap entries.
  50. + The protocol explicitly allows fewer entries; this fact is used by several X
  51. + servers (Apollo color servers, DEC QDSS servers, and perhaps others) to reserve
  52. + 2 slots for the cursor colors.  Unless the display hardware has a 2-color cursor
  53. + sprite, this is the only correct way to do a color cursor that I know of.
  54. +     (The Sun color cursor support on the MIT tape, which allocates the cursor
  55. + colors dynamically out of the default color map, is acknowledged by the author(s
  56. + )
  57. + to be wrong.  I don't know how IBM, HP or MacII color displays do cursors.)
  58. +     Anyway, I modified xcmap to accept any value it finds for dispcells <= 256.
  59. + It will draw the same square array of pixels, including the out-of-bounds ones,
  60. + but if you select an out-of-bounds pixel to display its RGB values, it will
  61. + just say that the pixel is out-of-bounds.  For what it's worth, this also allows
  62. + xcmap to run on monochrome displays, albeit rather boringly.
  63. + ------------------
  64. diff -c xcmap/patchlevel.h xcmapnew/patchlevel.h
  65. *** xcmap/patchlevel.h    Wed Feb  8 17:25:38 1989
  66. --- xcmapnew/patchlevel.h    Wed Feb  8 17:02:59 1989
  67. ***************
  68. *** 1 ****
  69. ! #define PATCHLEVEL 0
  70. --- 1 ----
  71. ! #define PATCHLEVEL 1
  72. diff -c xcmap/xcmap.c xcmapnew/xcmap.c
  73. *** xcmap/xcmap.c    Wed Feb  8 17:25:38 1989
  74. --- xcmapnew/xcmap.c    Wed Feb  8 17:15:12 1989
  75. ***************
  76. *** 106,123 ****
  77.       theVisual = DefaultVisual(theDisp,theScreen);
  78.   
  79.       dispcells = DisplayCells(theDisp, theScreen);
  80. !     if (dispcells!=16 && dispcells!=64 && dispcells != 256) {
  81. !         sprintf(tmpstr,"dispcells = %d.  This program can only deal with 4, 6, and 8-bit displays.",dispcells);
  82.           FatalError(tmpstr);
  83.           }
  84.   
  85. -     switch (dispcells) {
  86. -     case  16:  nxcells = nycells =  4;  break;
  87. -     case  64:  nxcells = nycells =  8;  break;
  88. -     case 256:  nxcells = nycells = 16;  break;
  89. -         }
  90. -     
  91.       /**************** Create/Open X Resources ***************/
  92.       if ((mfinfo = XLoadQueryFont(theDisp,FONT))==NULL) {
  93.          sprintf(tmpstr,"couldn't open '%s' font",FONT);
  94. --- 106,125 ----
  95.       theVisual = DefaultVisual(theDisp,theScreen);
  96.   
  97.       dispcells = DisplayCells(theDisp, theScreen);
  98. !     if (dispcells>256) {
  99. !         sprintf(tmpstr,"dispcells = %d.  This program can only deal with <= 8-bit displays.",dispcells);
  100.           FatalError(tmpstr);
  101.           }
  102. +     else if (dispcells>64)
  103. +         nxcells = nycells = 16;
  104. +     else if (dispcells>16)
  105. +         nxcells = nycells = 8;
  106. +     else if (dispcells>4)
  107. +         nxcells = nycells = 4;
  108. +     else
  109. +         nxcells = nycells = 2;
  110.   
  111.       /**************** Create/Open X Resources ***************/
  112.       if ((mfinfo = XLoadQueryFont(theDisp,FONT))==NULL) {
  113.          sprintf(tmpstr,"couldn't open '%s' font",FONT);
  114. ***************
  115. *** 339,344 ****
  116. --- 341,349 ----
  117.       static unsigned long pix, lastpix;
  118.       static int           pvaly;
  119.   
  120. +     if (x<0) x=0;  if (x>=WIDE) x=WIDE-1;
  121. +     if (y<0) y=0;  if (y>=HIGH) y=HIGH-1;
  122.       if (!pvalup) {    /* it's not up.  make it so */
  123.           if (y >= HIGH/2) pvaly = 0;  else pvaly = HIGH - 12;
  124.           pvalup = 1;
  125. ***************
  126. *** 356,368 ****
  127.   
  128.       XSetForeground(theDisp,theGC,fcol);
  129.           lastpix = def.pixel = pix;
  130. !         XQueryColor(theDisp, theCmap, &def);
  131. !         sprintf(tmpstr, "Pix %3ld = ($%04x, $%04x, $%04x)",
  132. !                          pix, def.red, def.green, def.blue);
  133.   
  134. !         /* make the hex uppercase */        
  135. !         for (sp=tmpstr+4; *sp; sp++) 
  136. !             if (islower(*sp)) *sp = toupper(*sp);
  137.   
  138.           XDrawImageString(theDisp,mainW,theGC,5,pvaly+10,tmpstr,strlen(tmpstr));
  139.           }
  140. --- 361,378 ----
  141.   
  142.       XSetForeground(theDisp,theGC,fcol);
  143.           lastpix = def.pixel = pix;
  144. !         if (pix<dispcells) {
  145. !             XQueryColor(theDisp, theCmap, &def);
  146. !             sprintf(tmpstr, "Pix %3ld = ($%04x, $%04x, $%04x)",
  147. !                              pix, def.red, def.green, def.blue);
  148.   
  149. !             /* make the hex uppercase */        
  150. !             for (sp=tmpstr+4; *sp; sp++) 
  151. !                 if (islower(*sp)) *sp = toupper(*sp);
  152. !             }
  153. !         else {
  154. !             sprintf(tmpstr, "Pix %3ld is out of legal range. ", pix);
  155. !             }
  156.   
  157.           XDrawImageString(theDisp,mainW,theGC,5,pvaly+10,tmpstr,strlen(tmpstr));
  158.           }
  159. -- 
  160. Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
  161. Moderator of comp.sources.x
  162.